var app = getApp();
var offset = 0;
var tg ;

function requestQuestion(that,d1,d2,d3){
  clearInterval(tg);
  wx.request({
    url: app.globalData.phpUrl + 'Question/api',
    method: "POST",
    header: { 'content-type': 'application/json' },
    data: { api_name: 'detail', openid: d1, questionnaire_id: d2, question_num:d3},
    success: function (data) {
      console.log('问卷id--' + d2, '第几个问题--' + d3);
      console.log(data.data);
      
      if(data.data.code == -2){
        wx.switchTab({
          url: '../index/index',
        })
      }

      var t2 = 1 ;
      
      var o = data.data.data.options;
      var l = o.length;
      for(var s = 0; s < l;s ++){
        if (o[s].type != 1) {
          t2 = 2;
          break 
        }
      };

      var delayTime = 6;
      if (data.data.data.type == 3){
        wx.getStorage({
          key: 'isSort',
          success: function (res) {
          },
          fail:function(){
            wx.showModal({
              title: '提示',
              content: '排序题目,拖动问题答案,可排列想要的顺序',
              confirmText: '好的',
              cancelText: '不再提示',
              success: function (res) {
                if (res.confirm) {
                } else if (res.cancel) {
                  wx.setStorage({
                    key: "isSort",
                    data: true
                  })
                }
              }
            })
          }
        })
        
      }
      var liD = data.data.data;
      liD.type = { t1: data.data.data.type, t2: t2 };
      function multiple(){
        var lll = liD.options.length;
        var arry = [];
        if (liD.select_option != 0){
          var optionArr = liD.select_option.split(",");
          for (var rr = 0; rr < lll; rr++) {
            if (optionArr.indexOf(liD.options[rr].id.toString()) == -1) {
              arry[rr] = false
            }else{
              arry[rr] = true
            }
          }
        }else{
          for (var rr = 0; rr < lll; rr++) {
              arry[rr] = false
          }
        }
        return arry
      };
      that.setData({
        question_num: d3,
        multiple: liD.type.t1 == 2 ? multiple() : '',
        lisData: liD,
        delay:false,
        delayTime: delayTime
      });
      if (that.data.lisData.select_option == '0') {
        that.setData({
          delay: true,
        });
        tg = setInterval(function () {
          delayTime--;
          that.setData({
            delayTime: delayTime
          });
          if (delayTime == 0) {
            clearInterval(tg);
            that.setData({
              delay: false,
            });
          }
        }, 1000)
      } else {
        if (that.data.lisData.type.t1 == 5) {
          for (var jj = 0; jj < l; jj++) {
            if (o[jj].id == that.data.lisData.select_option) {
              that.setData({
                next_num: o[jj].next_question == '0' ? Number(that.data.question_num) + 1 : o[jj].next_question
              })
            }
          }
        }
      };

      var query = wx.createSelectorQuery();
      for (var ttt = 0; ttt < l; ttt++) {
        query.select('#textL' + ttt).boundingClientRect()
        query.exec(function (res) {
          that.setData({
            textL: res
          });
        });
      };
      wx.hideLoading();
    }
  });

};

function insertCopy(arr,index, item){
  return arr.splice(index, 0, item);
};

function removeCopy(arr, dx){
  if (isNaN(dx) || dx > arr.length) { return false; }
  for (var i = 0, n = 0; i < arr.length; i++) {
    if (arr[i] != arr[dx]) {
      arr[n++] = arr[i]
    }
  }
  return arr.length -= 1
}


// pages/reply/reply.js
Page({
  data: {
    drapIndex:undefined,
    drapData:{
      listHeight:0,
      content:'',
      show:'none',
    },
    arrow: 'https://wjf.wayoxi.com/images/arrow.png',
    showReplay: false,
    next: false,
    isFold: true,
    canSort:false,
    animation: {},
    lisData: '',
    moreTitle: '',
    next_num:2,
    pre_num: 0,
    question_num:1,
    delay:false,
    multiple:[],
    region: ['全部', '全部', '全部'],
    customItem: '全部',
    company:0,
    isAuthorize: false
  },

  onLoad: function (options) {
    wx.showLoading({
      title: '加载问卷中...',
    })
    var that = this;
    if (options.article){
      wx.login({
        success: res => {
          wx.request({
            url: app.globalData.phpUrl +  'index/register',
            method: "POST",
            header: { 'content-type': 'application/json' },
            data: { code: res.code },
            success: function (data) {
              var opId = data.data.data.openid;
              wx.request({
                url: app.globalData.phpUrl + 'user/api',
                data: { api_name: 'naire_detail', openid: opId, questionnaire_id: options.id },
                method: 'POST',
                success: function (res) {
                  var resD = res.data.data;
                  if (resD.is_complete == 1){
                    wx.showToast({
                      image: "../../images/attend.png",
                      title: '您已回答过!',
                      duration: 2000
                    })
                    setTimeout(
                      function () {
                        wx.switchTab({
                          url: '../index/index',
                        })
                      }, 2000
                    )
                    return
                  };
                  if (resD.is_more == 1) {
                    wx.showToast({
                      title: '关注公众号答更多题!',
                      icon: 'none',
                      duration: 2000
                    })
                    setTimeout(
                      function () {
                        wx.switchTab({
                          url: '../index/index',
                        })
                      }, 2000
                    )
                    return
                  };
                  if (resD.is_verify != 1){
                    if (resD.is_verify == 2){
                      wx.showToast({
                        image: "../../images/attend.png",
                        title: '问卷审核未通过',
                        duration: 2000
                      })
                    } else if (resD.is_verify == 0){
                      wx.showToast({
                        image: "../../images/attend.png",
                        title: '问卷审核中',
                        duration: 2000
                      })
                    }
                    setTimeout(
                      function(){
                        wx.switchTab({
                          url: '../index/index',
                        })
                      },2000
                    )
                    return
                  } else if (resD.is_answer != 1){
                    wx.showToast({
                      image: "../../images/attend.png",
                      title: '你不符合标签要求',
                      duration: 2000
                    })
                    setTimeout(
                      function () {
                        wx.switchTab({
                          url: '../index/index',
                        })
                      }, 2000
                    )
                    return
                  }

                  that.setData({
                    cover: resD.cover,
                    title: resD.title,
                    question_id: parseInt(options.id),
                    question_count: resD.question_data.length,
                    opid: opId,
                    question_num: 1,
                    company:options.company || 0,
                    showReplay: true,
                  });

                  var query = wx.createSelectorQuery();
                  query.select('#titleTxt').boundingClientRect()
                  query.exec(function (res) {
                    if (res[0].width < 250) {
                      that.setData({
                        isFold: false
                      });
                    }
                  });

                  wx.showLoading({
                    title: '加载问题中...',
                  });

                  requestQuestion(that, opId, parseInt(options.id), that.data.question_num);
                }
              })

            }
          })
        }
      });
    }else{
      this.setData({
        cover: options.cover,
        title: options.title,
        question_id: parseInt(options.id),
        question_count: options.question_count,
        opid: options.opid || app.globalData.userData.openOId,
        question_num: options.question_num || 1,
        pre_num: options.question_num - 1 || 0,
        showReplay: true,
      });

      var query = wx.createSelectorQuery();
      query.select('#titleTxt').boundingClientRect()
      query.exec(function (res) {
        if (res[0].width < 250) {
          that.setData({
            isFold: false
          });
        }
      });

      wx.showLoading({
        title: '加载问题中...',
      });

      requestQuestion(that, options.opid, parseInt(options.id), that.data.question_num);
    }
  },

  radioChange: function (e) {
    var that = this;
    var iD = e.detail.value;
    var d = that.data.lisData.options;
    var dLendth = that.data.lisData.options.length;
   

    var query = wx.createSelectorQuery();
    for (var ttt = 0; ttt < dLendth; ttt++) {
      query.select('#textL' + ttt).boundingClientRect()
      query.exec(function (res) {
        that.setData({
          textL: res
        });
      });
    };
    
    //如果是逻辑题   设置下一题
    if (that.data.lisData.type.t1 == 5){
      for (var uu = 0; uu < dLendth; uu++){
        if (iD == d[uu].id){
           that.setData({
             next_num: d[uu].next_question == '0' ? Number(that.data.question_num) + 1 : d[uu].next_question
           })
        };
      };
    };

    that.setData({
      ['lisData.options']:d,
      ['lisData.select_option']: iD,
    });
  },

  checkboxChange: function (e) {
    var that = this;
    var iD = e.detail.value;
    var d = that.data.lisData.options;
    var dLendth = that.data.lisData.options.length;
    
    var multiple = that.data.multiple;

    that.setData({
      ['lisData.options']: d,
      ['lisData.select_option']: iD,
    });

    if (that.data.lisData.select_option != 0) {
      var ld = that.data.lisData;
      for (var rr = 0; rr < dLendth; rr++) {
        if (ld.select_option.indexOf(ld.options[rr].id.toString()) == '-1') {
          multiple[rr] = false
        } else {
          multiple[rr] = true
        }
      }
    } else {
      for (var rr = 0; rr < dLendth; rr++) {
          multiple[rr] = false
      }
    };
    that.setData({
      multiple: multiple
    });
  },
  
  moreTtile:function(){
    var that = this;
    that.setData({
      isFold:false
    });
    var query = wx.createSelectorQuery();
    query.select('#moreContent').boundingClientRect();
    query.exec(function (res) {
      that.animation.bottom(- res[0].height).step({ duration: 300 });
      that.setData({
        animation: that.animation.export(),
      });
    })
  },

  defaultTtile: function () {
    var that = this;
    that.setData({
      isFold: true
    });
    that.animation.bottom('0rpx').step({ duration: 300 });
    that.setData({
      animation: that.animation.export(),
    });
  },
  nex2:function(e){
    var that = this;
    if (e.detail.rawData) {
      app.globalData.userInfo = JSON.parse(e.detail.rawData);

      if (e.currentTarget.dataset.use) {
        return;
      };
      var that = this;
      var isFull = false;
      var question_id = '';
      var da = that.data.lisData;
      var le = that.data.lisData.options.length;
      switch (da.type.t1) {
        case 1:
          if (da.select_option != '0' && da.select_option[0] != undefined) {
            isFull = true;
          };
          if (isFull) {
            wx.showLoading({
              title: '下一题...',
            });
            wx.request({
              url: app.globalData.phpUrl + 'Question/api',
              method: "POST",
              data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option },
              success: function (data) {
                if (data.data.code == 2) {
                  wx.redirectTo({
                    url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                  });
                  return
                }
                if (data.data.code == -1) {
                  wx.showToast({
                    title: data.data.msg + '!',
                    icon: 'none',
                    duration: 2000,
                  })
                  return
                }
                that.setData({
                  next_num: Number(that.data.question_num) + 1,
                  pre_num: Number(that.data.question_num)
                })
                requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
              }
            })

          } else {
            wx.showToast({
              title: '未选择选项!',
              icon: 'none',
              duration: 2000,
            })
          }
          break;

        case 2:

          var select_option;
          if (typeof da.select_option == 'string') {
            select_option = da.select_option.split(',');
          } else {
            select_option = da.select_option
          }


          if (select_option != '0' && select_option[0] != undefined) {
            isFull = true;
          };

          if (isFull) {
            if (da.select_num != 0 && da.select_num != select_option.length) {
              wx.showToast({
                title: '必选' + da.select_num + '题',
                icon: 'none',
                duration: 2000,
              });
              break
            }
            wx.showLoading({
              title: '下一题...',
            });
            wx.request({
              url: app.globalData.phpUrl + 'Question/api',
              method: "POST",
              data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option.toString() },
              success: function (data) {
                if (data.data.code == 2) {
                  wx.redirectTo({
                    url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                  });
                  return
                }
                if (data.data.code == -1) {
                  wx.showToast({
                    title: data.data.msg + '!',
                    icon: 'none',
                    duration: 2000,
                  })
                  return
                }
                that.setData({
                  next_num: Number(that.data.question_num) + 1,
                  pre_num: Number(that.data.question_num)
                })
                requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
              }
            })

          } else {
            wx.showToast({
              title: '未选择选项!',
              icon: 'none',
              duration: 2000,
            })
          }
          break;



        case 3:
          if (da.select_option != '0' && da.select_option[0] != undefined) {
            isFull = true;
          };
          if (isFull) {
            wx.showLoading({
              title: '下一题...',
            });
            wx.request({
              url: app.globalData.phpUrl + 'Question/api',
              method: "POST",
              data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option },
              success: function (data) {
                if (data.data.code == 2) {
                  wx.redirectTo({
                    url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                  });
                  return
                };

                if (data.data.code == -1) {
                  wx.showToast({
                    title: data.data.msg + '!',
                    icon: 'none',
                    duration: 2000,
                  })
                  return
                }
                that.setData({
                  next_num: Number(that.data.question_num) + 1,
                  pre_num: Number(that.data.question_num)
                })
                requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
              }
            })

          } else {
            wx.showToast({
              title: '未选择选项!',
              icon: 'none',
              duration: 2000,
            })
          }
          break;
        case 4:
          var region = that.data.region[0] + ' ' + that.data.region[1] + ' ' + that.data.region[2];
          if (that.data.region[0] == '全部') {
            wx.showToast({
              title: '请选择地区!',
              icon: 'none',
              duration: 2000,
            });
            return
          }
          wx.showLoading({
            title: '下一题...',
          });
          wx.request({
            url: app.globalData.phpUrl + 'Question/api',
            method: "POST",
            data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: region },
            success: function (data) {
              if (data.data.code == 2) {
                wx.redirectTo({
                  url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                });
                return
              };
              if (data.data.code == -1) {
                wx.showToast({
                  title: data.data.msg + '!',
                  icon: 'none',
                  duration: 2000,
                })
                return
              }
              that.setData({
                next_num: Number(that.data.question_num) + 1,
                pre_num: Number(that.data.question_num)
              });
              requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
            }
          })

          break;
        case 5:
          if (da.select_option != '0' && da.select_option[0] != undefined) {
            isFull = true;
          };
          if (isFull) {
            wx.showLoading({
              title: '下一题...',
            });
            wx.request({
              url: app.globalData.phpUrl + 'Question/api',
              method: "POST",
              data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option },
              success: function (data) {
                if (data.data.code == 2) {
                  wx.redirectTo({
                    url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                  });
                  return
                };
                if (data.data.code == -1) {
                  wx.showToast({
                    title: data.data.msg + '!',
                    icon: 'none',
                    duration: 2000,
                  })
                  return
                }
                that.setData({
                  pre_num: Number(that.data.question_num)
                });
                requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
              }
            })

          } else {
            wx.showToast({
              title: '未选择选项!',
              icon: 'none',
              duration: 2000,
            })
          }
          break;
        case 6:
          break;
        default:
        // n 与 case 1 ~ case 4 不同时执行的代码
      };
      
      wx.request({
        url: app.globalData.phpUrl + 'index/getUnionId',
        method: "POST",
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        data: { openid: app.globalData.userData.openOId, encrypteddata: e.detail.encryptedData, iv: e.detail.iv },
        success: function (es) {
        }
      })
      that.setData({
        isAuthorize: true
      });
    } else {
      that.setData({
        isAuthorize: false
      });
      wx.showToast({
        title: '未获取你的信息,请接受授权获取您的信息!',
        icon: 'none',
        duration: 2000,
      });
    }
  },

  nex:function(e){

    if (e.currentTarget.dataset.use) {
      return;
    };
    var that = this;
    var isFull = false;
    var question_id = '';
    var da = that.data.lisData;
    var le = that.data.lisData.options.length;
    switch(da.type.t1){
      case 1:
        if (da.select_option != '0' && da.select_option[0] != undefined) {
                isFull = true;
              };
              if (isFull) {
                wx.showLoading({
                  title: '下一题...',
                });
                wx.request({
                  url: app.globalData.phpUrl + 'Question/api',
                  method: "POST",
                  data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option },
                  success: function (data) {
                    if (data.data.code == 2) {
                      wx.redirectTo({
                        url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                      });
                      return
                    }
                    if (data.data.code == -1) {
                      wx.showToast({
                        title: data.data.msg + '!',
                        icon: 'none',
                        duration: 2000,
                      })
                      return
                    }
                    that.setData({
                      next_num: Number(that.data.question_num) + 1,
                      pre_num: Number(that.data.question_num)
                    })
                    requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
                  }
                })

              } else {
                wx.showToast({
                  title: '未选择选项!',
                  icon: 'none',
                  duration: 2000,
                })
              }
         break;
      
      case 2:
        var select_option;
        if(typeof da.select_option == 'string'){
          select_option = da.select_option.split(',');
        }else{
          select_option = da.select_option
        }
      
        if (select_option != '0' && select_option[0] != undefined) {
          isFull = true;
        };
        if (isFull) {
          if (da.select_num != 0 && da.select_num != select_option.length){
            wx.showToast({
              title: '必选' + da.select_num+'题',
              icon: 'none',
              duration: 2000,
            });
            break
          }
          wx.showLoading({
            title: '下一题...',
          });
          
          wx.request({
            url: app.globalData.phpUrl + 'Question/api',
            method: "POST",
            data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option.toString() },
            success: function (data) {
              if (data.data.code == 2) {
                wx.redirectTo({
                  url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                });
                return
              }
              if (data.data.code == -1) {
                wx.showToast({
                  title: data.data.msg + '!',
                  icon: 'none',
                  duration: 2000,
                })
                return
              }
              that.setData({
                next_num: Number(that.data.question_num) + 1,
                pre_num: Number(that.data.question_num)
              })
              requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
            }
          })

        } else {
          wx.showToast({
            title: '未选择选项!',
            icon: 'none',
            duration: 2000,
          })
        }
        break;
      
 
 
      case 3:
        if (da.select_option != '0' && da.select_option[0] != undefined) {
                isFull = true;
              };
              if (isFull) {
                wx.showLoading({
                  title: '下一题...',
                });
                wx.request({
                  url: app.globalData.phpUrl + 'Question/api',
                  method: "POST",
                  data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option },
                  success: function (data) {
                    if (data.data.code == 2) {
                      wx.redirectTo({
                        url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                      });
                      return
                    };

                    if (data.data.code == -1) {
                      wx.showToast({
                        title: data.data.msg + '!',
                        icon: 'none',
                        duration: 2000,
                      })
                      return
                    }
                    that.setData({
                      next_num: Number(that.data.question_num) + 1,
                      pre_num: Number(that.data.question_num)
                    })
                    requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
                  }
                })

              } else {
                wx.showToast({
                  title: '未选择选项!',
                  icon: 'none',
                  duration: 2000,
                })
              }
        break;
      case 4:
              var region = that.data.region[0] + ' ' + that.data.region[1] + ' ' + that.data.region[2];
              if (that.data.region[0] == '全部'){
                wx.showToast({
                  title: '请选择地区!',
                  icon: 'none',
                  duration: 2000,
                });
                return
              }
              wx.showLoading({
                title: '下一题...',
              });
              wx.request({
                url: app.globalData.phpUrl + 'Question/api',
                method: "POST",
                data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: region },
                success: function (data) {
                  if (data.data.code == 2) {
                    wx.redirectTo({
                      url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                    });
                    return
                  };
                  if (data.data.code == -1) {
                    wx.showToast({
                      title: data.data.msg + '!',
                      icon: 'none',
                      duration: 2000,
                    })
                    return
                  }
                  that.setData({
                    next_num: Number(that.data.question_num) + 1,
                    pre_num: Number(that.data.question_num)
                  });
                  requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
                }
              })

        break;
      case 5:
        if (da.select_option != '0' && da.select_option[0] != undefined) {
                isFull = true;
              };
              if (isFull) {
                wx.showLoading({
                  title: '下一题...',
                });
                wx.request({
                  url: app.globalData.phpUrl + 'Question/api',
                  method: "POST",
                  data: { api_name: 'answer', openid: that.data.opid, question_id: da.id, content: da.select_option },
                  success: function (data) {
                    if (data.data.code == 2) {
                      wx.redirectTo({
                        url: './finish/finish?id=' + that.data.question_id + '&money=' + data.data.data.money
                      });
                      return
                    };
                    if (data.data.code == -1) {
                      wx.showToast({
                        title: data.data.msg + '!',
                        icon: 'none',
                        duration: 2000,
                      })
                      return
                    }
                    that.setData({
                      pre_num: Number(that.data.question_num)
                    });
                    requestQuestion(that, that.data.opid, that.data.question_id, that.data.next_num);
                  }
                })

              } else {
                wx.showToast({
                  title: '未选择选项!',
                  icon: 'none',
                  duration: 2000,
                })
              }
        break;
      case 6:
        break;
      default:
      // n 与 case 1 ~ case 4 不同时执行的代码
    }
  },

  pre: function (e) {
    clearInterval(tg);
    var that = this;
    var preview = that.data.pre_num;
    if (preview == 0){
      wx.showToast({
        title: '没有上一题',
        icon: 'none',
        duration: 2000,
      })
      return
    };

    wx.showLoading({
      title: '上一题...',
    });

    that.setData({
      pre_num:that.data.pre_num -1,
      question_num: that.data.question_num - 1,
      delay: false
    });

    requestQuestion(that, that.data.opid, that.data.question_id, preview);
  },

  onShow: function () {
    var that = this;
    that.animation = wx.createAnimation({
      duration: 1000,
      transformOrigin: "100% 0",
      timingFunction: "ease",
    });

    that.setData({
      animation: that.animation.export(),
    });

    if (app.globalData.userInfo) {
      that.setData({
        isAuthorize: true
      });
    } else {
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo;
          that.setData({ userInfo: res.userInfo });
          that.setData({
            isAuthorize: true
          })
        },
        fail: res => {
          isAuthorize: false
        }
      })
    }
  },
  
  previewImage:function(t){
    var url = t.currentTarget.dataset.url
    wx.previewImage({
      current: url, // 当前显示图片的http链接
      urls: [url] // 需要预览的图片http链接列表
    })
  },

  bindRegionChange: function (e) {
    this.setData({
      region: e.detail.value
    })
  },

  sortStart:function(e){
    var that = this;
    offset = e.changedTouches[0].pageY;
  },

  sortMove: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var xc = e.changedTouches[0].pageY - offset;

    if (parseInt(xc / 60) == 0) {
      return
    }
    that.setData({
      drapIndex: index + parseInt(xc / 60)
    });
  },

  sortEnd: function (e) {
   
    var that = this;
    var xc = e.changedTouches[0].pageY - offset;
    var index = e.currentTarget.dataset.index;
    var dArr = that.data.lisData.options;
    var textL = that.data.textL;
    var select_option = [];
    
    that.setData({
      drapIndex: 'undefined',
    });

    if (parseInt(xc / 60) == 0) {
      that.setData({
        ['lisData.options']: dArr,
        textL: textL
      });
      return
    };
    
    var indexData = dArr[index];
    var indexTextL = textL[index];

    removeCopy(dArr, index)
    removeCopy(textL, index)
    insertCopy(dArr, index + parseInt(xc / 60), indexData)
    insertCopy(textL, index + parseInt(xc / 60), indexTextL)

    for(var ee = 0; ee < dArr.length; ee++){
      select_option[ee] = dArr[ee].id;
    }

    that.setData({
      ['lisData.options']: dArr,
      ['lisData.select_option']: select_option.toString(),
      textL: textL
    });
  },

  sortStart2:function(e){
    var that = this;
    offset = e.changedTouches[0].pageX;
  },

  sortMove2: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var xc = e.changedTouches[0].pageX - offset;
    if (parseInt(xc / 88) == 0 || index + parseInt(xc / 88) == -1 || index + parseInt(xc / 88) > that.data.lisData.options.length - 1) {
      return
    }
    that.setData({
      drapIndex: index + parseInt(xc / 88)
    });
  },
  
  sortEnd2: function (e) {

    var that = this;
    var xc = e.changedTouches[0].pageX - offset;
    var index = e.currentTarget.dataset.index;
    var dArr = that.data.lisData.options;
    var select_option = [];
    
    if (parseInt(xc / 88) == 0 || index + parseInt(xc / 88) == -1 || index + parseInt(xc / 88) > dArr.length - 1) {
      that.setData({
        ['lisData.options']: dArr,
      });
      return
    }

    that.setData({
      drapIndex: 'undefined',
    });

    if (parseInt(xc / 88) == 0) {
      that.setData({
        ['lisData.options']: dArr,
      });
      return
    };

    var indexData = dArr[index];
    removeCopy(dArr, index)
    insertCopy(dArr, index + parseInt(xc / 88), indexData)

    for (var ee = 0; ee < dArr.length; ee++) {
      select_option[ee] = dArr[ee].id;
    }

    that.setData({
      ['lisData.options']: dArr,
      ['lisData.select_option']: select_option.toString(),
    });
  },

  seeAll: function (e) {
    wx.showModal({
      title: '查看',
      content: e.currentTarget.dataset.content,
      showCancel: false,
      confirmText: '确定'
    })

  }
})